﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MySql.Data.MySqlClient;

namespace ConsoleApplication
{
    public class Singleton
    {
        private static Singleton dbInstance;
        private readonly MySqlConnection conn = new MySqlConnection("Server=localhost;Database=newstore;Uid=root");        
      
        private Singleton()
        {
        }

        public static Singleton getDbInstance()
        {
            if (dbInstance == null)
            {
                Console.WriteLine("Création de la connexion");
                dbInstance = new Singleton();
            }
            return dbInstance;
        }

        public MySqlConnection GetDBConnection()
        {
            try
            {
                conn.Open();
                Console.WriteLine("Connected");
            }
            catch (MySqlException e)
            {
                Console.WriteLine("Not connected : "+e.ToString());
                Console.ReadLine();
            }

            return conn;
            
        }
    }
}